/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package session;

import entities.Cliente;
import entities.DettaglioOrdine;
import entities.Ordine;
import entities.Prodotto;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import session.exceptions.OrderException;

/**
 *
 * @author sflesca
 */
@Stateless
public class OrderManager implements OrderManagerLocal {
    @EJB
    private OrdineFacade ordineFacade;

    @Override
    public void creaOrdine(Cliente cliente, List<Prodotto> prodotti) throws OrderException {
    
        Ordine ordine = new Ordine();
        ordine.setCliente(cliente);
        cliente.getOrdini().add(ordine);
        for(Prodotto p:prodotti){
            DettaglioOrdine dett = new DettaglioOrdine();
            dett.setQta(1);
            dett.setOrdine(ordine);
            dett.setProdotto(p);
            ordine.getDettagli().add(dett);
        }
        ordineFacade.create(ordine);
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
}
